using System.IO;
using System.Text;

namespace FileManagement
{
    public partial class Form1 : Form
    {
        string filepath1 = null;
        string filepath2 = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

            if (filepath1 == null)
            {
                filepath1 = label1.Text;
            }
            else
            {
                if (filepath2 == null)
                {
                    filepath2 = label1.Text;
                }
                else
                {
                    filepath1 = null;
                    filepath2 = null;
                }
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            if (filepath1 == null)
            {
                filepath1 = label2.Text;
            }
            else
            {
                if (filepath2 == null)
                {
                    filepath2 = label2.Text;
                }
                else
                {
                    filepath1 = null;
                    filepath2 = null;
                }
            }
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            if (filepath1 == null)
            {
                filepath1 = label3.Text;
            }
            else
            {
                if (filepath2 == null)
                {
                    filepath2 = label3.Text;
                }
                else
                {
                    filepath1 = null;
                    filepath2 = null;
                }
            }
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            if (filepath1 == null)
            {
                filepath1 = label4.Text;
            }
            else
            {
                if (filepath2 == null)
                {
                    filepath2 = label4.Text;
                }
                else
                {
                    filepath1 = null;
                    filepath2 = null;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (filepath1 != null && filepath2 != null)
            {
                try
                {
                    string content1 = File.ReadAllText("C:\\Users\\w\\Desktop\\FileManagement\\resourse\\" + filepath1, Encoding.UTF8);
                    string content2 = File.ReadAllText("C:\\Users\\w\\Desktop\\FileManagement\\resourse\\" + filepath2, Encoding.UTF8);
                    label5.Text = content1;
                    label6.Text = content2;
                    string content3 = content1 + content2;
                    FileStream fileStream = File.Create("C:\\Users\\w\\Desktop\\FileManagement\\resourse\\5.txt");
                    fileStream.Close();
                    File.WriteAllText("C:\\Users\\w\\Desktop\\FileManagement\\resourse\\5.txt",content3);
                }
                catch (IOException ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            else if (filepath1 != null && filepath2 == null)
            {
                label6.Text = "file2 is not selected";
            }
            else if (filepath1 == null && filepath2 != null)
            {
                label5.Text = "file1 is not selected";
            }
            else
            {
                label6.Text = "file2 is not selected";
                label5.Text = "file1 is not selected";
            }
        }
    }
}